package com.yt.sys.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yt.sys.models.entity.SysRole;
import com.yt.sys.models.service.ISysRoleService;
import com.yt.sys.server.mapper.SysRoleMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService(interfaceClass = ISysRoleService.class)
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    /**
     * 根据角色名称查找角色
     * @param roleName 角色名称
     * @return 角色信息
     */
    public SysRole getByRoleName(String roleName) {
        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("role_name", roleName);
        queryWrapper.eq("is_delete", 0);
        return this.getOne(queryWrapper);
    }

    /**
     * 获取所有未删除的角色
     * @return 角色列表
     */
    public List<SysRole> getAllActiveRoles() {
        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", 0);
        queryWrapper.orderByDesc("create_time");
        return this.list(queryWrapper);
    }
}